Skip to content

🐛 Fix nested object filtering in JSONB WHERE clauses#71

Merged
evoludigit merged 1 commit into
devfrom
fix-nested-filter-bug
Sep 28, 2025
Merged

🐛 Fix nested object filtering in JSONB WHERE clauses#71
evoludigit merged 1 commit into
devfrom
fix-nested-filter-bug

Conversation

@evoludigit
Copy link
Copy Markdown
Contributor

Summary

  • Fixed incorrect SQL generation for nested object filters in GraphQL WHERE clauses
  • Nested filters now correctly generate JSONB paths like data -> 'machine' ->> 'id' instead of accessing fields at root level

Problem

When using nested object filters in GraphQL WHERE clauses with JSONB-backed tables, FraiseQL was generating incorrect SQL that didn't properly handle the nested object path. This caused filters to fail silently and return unfiltered results.

Before (incorrect):

WHERE (data ->> 'id') = '01513100-0000-0000-0000-000000000066'

After (correct):

WHERE (data -> 'machine' ->> 'id') = '01513100-0000-0000-0000-000000000066'

Changes

  • Modified where_generator.py to pass parent_path through the to_sql() method chain
  • Added _build_nested_path() helper function for cleaner path construction
  • Updated the DynamicType Protocol to include the new parameter
  • Fixed logical operators (AND, OR, NOT) to also pass parent_path
  • Enhanced tests to validate correct JSONB path generation
  • Added deep nesting test coverage (3+ levels)
  • Updated existing test that expected the old (incorrect) behavior

Test plan

  • All existing tests pass (3283 tests)
  • New test validates correct nested path generation
  • Deep nesting (3+ levels) test added and passes
  • Ruff linter passes
  • No regressions introduced

🤖 Generated with Claude Code

Fixed incorrect SQL generation for nested object filters in GraphQL WHERE clauses.
The bug caused filters on nested objects to access fields at the root level instead
of the correct nested path in JSONB columns.

Changes:
- Modified where_generator.py to pass parent_path through the to_sql() chain
- Added _build_nested_path() helper for cleaner path construction
- Enhanced tests to validate correct JSONB path generation
- Added deep nesting test coverage (3+ levels)

Before: WHERE (data ->> 'id') = '...'  # Incorrect root-level access
After:  WHERE (data -> 'machine' ->> 'id') = '...'  # Correct nested path

Fixes the issue reported in fraiseql_nested_filter_bug_report.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@evoludigit evoludigit merged commit f75f37e into dev Sep 28, 2025
5 checks passed
@evoludigit evoludigit deleted the fix-nested-filter-bug branch September 28, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant